package cn.hh.wechatkit.pojo.message.imp.commumication;

import cn.hh.wechatkit.pojo.message.imp.Wx_BaseMsg;
import cn.hhchat.kit.xml.XmlUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import java.util.Map;

/**
 * Created this one by HMH on 2017/7/11.
 */
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Wx_VideoMsg extends Wx_BaseMsg {

    private String mediaId;
    private String title;
    private String description;

    //TODO 接受视频消息

    public Wx_VideoMsg(Map<String, String> map) {
        super(map);
    }

    @Override
    public String MsgToXml() {
        //生成xml文档
        Document document = DocumentHelper.createDocument();
        document.setXMLEncoding("utf-8");
        Element root = document.addElement("xml");
        //构造 ToUserName
        Element ToUserName = root.addElement("ToUserName")
                .addText(XmlUtil.genCdataAttr(this.getToUserName()));
        //添加 FromUserName
        Element FromUserName = root.addElement("FromUserName")
                .addText(XmlUtil.genCdataAttr(this.getFromUserName()));
        //构造 CreateTime
        Element createTime = root.addElement("CreateTime")
                .addText(XmlUtil.genCdataAttr(String.valueOf(this.getCreateTime())));
        //构造 MsgType
        Element msgType = root.addElement("MsgType")
                .addText(XmlUtil.genCdataAttr("video"));

        //构造 Video
        Element video = root.addElement("Video");
        video.addElement("MediaId")
                .addText(XmlUtil.genCdataAttr(this.mediaId));
        video.addElement("Title")
                .addText(XmlUtil.genCdataAttr(this.title));
        video.addElement("Description")
                .addText(XmlUtil.genCdataAttr(this.description));

        return document.asXML();
    }
}
